<?php
/**
 *  删除图片
 */

//拼接用户图片上传目录
$syspath = $_SERVER['DOCUMENT_ROOT'];
$userUploadPath = getcwd() . DIRECTORY_SEPARATOR . "upload" . DIRECTORY_SEPARATOR .$cid. DIRECTORY_SEPARATOR ."image";
$files = array();
function traverse($path = '.') {
	global $files;
	$current_dir = opendir($path);    //opendir()返回一个目录句柄,失败返回false
	while(($file = readdir($current_dir)) !== false) {    //readdir()返回打开目录句柄中的一个条目
		$sub_dir = $path . DIRECTORY_SEPARATOR . $file;    //构建子目录路径
		if($file == '.' || $file == '..') {
			continue;
		} else if(is_dir($sub_dir)) {
			traverse($sub_dir);
		} else {
			array_push($files, $sub_dir);
		}
	}
}
traverse($userUploadPath);

$return = array();
$return['status'] = 'error';
foreach($files as $key =>$value){
	if(strstr($value,$img)){
		$return['status'] = (unlink($value)) ? "ok" : "error";
	}
}
return json_encode($return);